package cn.z2huo.demo.spring.webmvc;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.util.Arrays;

/**
 * <p>
 *
 * @author z2huo
 */
@SpringBootApplication(scanBasePackages = {"cn.z2huo.demo.spring.webmvc"})
//@ComponentScan(basePackages = {"cn.z2huo.demo.springmvc"})
public class SpringWebmvcApp {

    public static void main(String[] args) {
        System.out.println();
        System.out.println(Arrays.toString(args));

        ConfigurableApplicationContext appContext = SpringApplication.run(SpringWebmvcApp.class, args);
        ConfigurableEnvironment environment = appContext.getEnvironment();

        System.out.println(environment.getProperty("zyz.name"));
        System.out.println(environment.getProperty("zyf.name"));
        // zyh.name 没有加 -- 前缀，获取不到，但是 args 数组中可以获取到
        System.out.println(environment.getProperty("zyh.name"));
        System.out.println();

        System.out.println();
        System.out.println("===== system env =====");
        environment.getSystemEnvironment().forEach((k, v) -> {
            System.out.println(k + " = " + v);
        });

        System.out.println();
        System.out.println("===== system properties =====");
        environment.getSystemProperties().forEach((k, v) -> {
            System.out.println(k + " = " + v);
        });

        System.out.println();
        System.out.println(Arrays.toString(environment.getDefaultProfiles()));
        System.out.println(Arrays.toString(environment.getActiveProfiles()));
    }

}
